package org.afs.gescol.gwt.client;

import org.afs.gescol.gwt.client.controller.AppController;

import org.afs.gescol.gwt.client.factory.AppClientFactory;
import org.afs.gescol.gwt.client.service.GetServicesGwt;
import org.afs.gescol.gwt.shared.GlobalConstantesModel;
import org.scub.foundation.framework.gwt.module.client.util.popup.error.ErrorPopup;
import org.scub.foundation.framework.gwt.module.client.util.popup.loading.LoadingPopup;
import org.scub.foundation.framework.gwt.module.client.util.popup.util.ErrorPopupConfiguration;
import org.scub.foundation.framework.gwt.module.client.util.popup.util.LoadingPopupConfiguration;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootLayoutPanel;

/**
 * Application entry point.
 * @author Anthony GUILLEMETTE (anthony.guillemette@scub.net)
 */
public final class ClientEntryPointGwt implements EntryPoint {

    /**
     * {@inheritDoc}
     */
    public void onModuleLoad() {
        LoadingPopup.afficher(new LoadingPopupConfiguration("Loading..."));
        GetServicesGwt.App.getInstance().getGlobalConstantesModel(new AsyncCallback<GlobalConstantesModel>() {
            @Override
            public void onSuccess(GlobalConstantesModel result) {
                final AppController app = AppClientFactory.getAppController();
                app.setConstantesModel(result);
                app.showPresenter(RootLayoutPanel.get());
                LoadingPopup.stopAll();
            }
            @Override
            public void onFailure(Throwable caught) {
                LoadingPopup.stopAll();
                
                ErrorPopup.afficher(new ErrorPopupConfiguration("Loading error."));
            }
        });
    }
}